 
$(function () {
    // 一号厅
    var price = 48; /*票价*/
    var $cart = $('#main #selected-seats'),
         /*座位区*/
         $counter = $('#main #counter'),
        /*票数*/
         $total = $('#main #total'); /*总计金额*/

    var sc = $('#main #seat-map').seatCharts({
        map: [ /*座位图*/
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            '__________',
            'aaaaaaaa__',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aaaaaaaaaa',
            'aa__aa__aa'
        ],
        naming: {
            top: false,
            getLabel: function(character, row, column) {
                return column;
            }
        },
        legend: { /*定义图例*/
            node: $('#main #legend'),
            items: [
                ['a', 'available', '可选座'],
                ['a', 'unavailable', '已售出']
            ]
        },
        click: function() { /*点击事件*/
            if (this.status() == 'available') { /*可选座*/
                $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
                    .attr('id', 'cart-item-' + this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart);

                $counter.text(sc.find('selected').length + 1);
                $total.text(recalculateTotal(sc) + price);

                return 'selected';
            } else if (this.status() == 'selected') { /*已选中*/
                /*更新数量*/
                $counter.text(sc.find('selected').length - 1);
                /*更新总计*/
                $total.text(recalculateTotal(sc) - price);

                /*删除已预订座位*/
                $('#main #cart-item-' + this.settings.id).remove();
                /*可选座*/
                return 'available';
            } else if (this.status() == 'unavailable') { /*已售出*/
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    /*已售出的座位*/
    sc.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');

    /*计算总金额*/
    function recalculateTotal(sc) {
        var total = 0;
        sc.find('selected').each(function() {
            total += price;
        });

        return total;
    }



    // 2号厅
    var price2 = 40; /*票价*/
    var $cart2 = $('#main2 #selected-seats'),
         /*座位区*/
         $counter2 = $('#main2 #counter'),
        /*票数*/
         $total2 = $('#main2 #total'); /*总计金额*/

    var sc2 = $('#main2 #seat-map').seatCharts({
        map: [ /*座位图*/
            'bbbbbbbbbb',
            'bbbbbbbbbb',
            '__________',
            'bbbbbbbb__',
            'bbbbbbbbbb',
            'bbbbbbbbbb',
            '__________',
            'bbbbbbbbbb',
            '__bbbbbbbb',
            'bbbbbbbbbb',
            '_bbb_bbbb_'
        ],
        naming: {
            top: false,
            getLabel: function(character, row, column) {
                return column;
            }
        },
        legend: { /*定义图例*/
            node: $('#main2 #legend'),
            items: [
                ['b', 'available', '可选座'],
                ['b', 'unavailable', '已售出']
            ]
        },
        click: function() { /*点击事件*/
            if (this.status() == 'available') { /*可选座*/
                $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
                    .attr('id', 'cart-item-' + this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart2);

                $counter2.text(sc2.find('selected').length + 1);
                $total2.text(recalculateTotal2(sc2) + price2);

                return 'selected';
            } else if (this.status() == 'selected') { /*已选中*/
                /*更新数量*/
                $counter2.text(sc2.find('selected').length - 1);
                /*更新总计*/
                $total2.text(recalculateTotal2(sc2) - price2);

                /*删除已预订座位*/
                $('#main2 #cart-item-' + this.settings.id).remove();
                /*可选座*/
                return 'available';
            } else if (this.status() == 'unavailable') { /*已售出*/
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    /*已售出的座位*/
    sc2.get(['4_4', '4_5', '4_6', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');

    /*计算总金额*/
    function recalculateTotal2(sc2) {
        var total2 = 0;
        sc2.find('selected').each(function() {
            total2 += price2;
        });

        return total2;
    }


    // 3号厅
    var price3 = 56; /*票价*/
    var $cart3 = $('#main3 #selected-seats'),
         /*座位区*/
         $counter3 = $('#main3 #counter'),
        /*票数*/
         $total3 = $('#main3 #total'); /*总计金额*/

    var sc3 = $('#main3 #seat-map').seatCharts({
        map: [ /*座位图*/
            'cccccccccc',
            'cccccccccc',
            'cccccccccc',
            '__________',
            'cccccccccc',
            'cccccccccc',
            'cccccccccc',
            'cccccccccc',
            'cccccccccc',
            'cc__cc__cc'
        ],
        naming: {
            top: false,
            getLabel: function(character, row, column) {
                return column;
            }
        },
        legend: { /*定义图例*/
            node: $('#main3 #legend'),
            items: [
                ['c', 'available', '可选座'],
                ['c', 'unavailable', '已售出']
            ]
        },
        click: function() { /*点击事件*/
            if (this.status() == 'available') { /*可选座*/
                $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
                    .attr('id', 'cart-item3-' + this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart3);

                $counter3.text(sc3.find('selected').length + 1);
                $total3.text(recalculateTotal3(sc3) + price3);

                return 'selected';
            } else if (this.status() == 'selected') { /*已选中*/
                /*更新数量*/
                $counter3.text(sc3.find('selected').length - 1);
                /*更新总计*/
                $total3.text(recalculateTotal3(sc3) - price3);

                /*删除已预订座位*/
                $('#main3 #cart-item3-' + this.settings.id).remove();
                /*可选座*/
                return 'available';
            } else if (this.status() == 'unavailable') { /*已售出*/
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    /*已售出的座位*/
    sc3.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');

    /*计算总金额*/
    function recalculateTotal3(sc3) {
        var total3 = 0;
        sc3.find('selected').each(function() {
            total3 += price3;
        });

        return total3;
    }



    // 4号厅
    var price4 = 50; /*票价*/
    var $cart4 = $('#main4 #selected-seats'),
         /*座位区*/
         $counter4 = $('#main4 #counter'),
        /*票数*/
         $total4 = $('#main4 #total'); /*总计金额*/

    var sc4 = $('#main4 #seat-map').seatCharts({
        map: [ /*座位图*/
            'dddddddddd',
            'dddddddddd',
            'dddddddddd',
            '__________',
            'dddddddddd',
            'dddddddddd',
            'dddddddddd',
            '__________',
            'dddddddddd',
            'dddddddddd',
            'dddddddddd'
        ],
        naming: {
            top: false,
            getLabel: function(character, row, column) {
                return column;
            }
        },
        legend: { /*定义图例*/
            node: $('#main4 #legend'),
            items: [
                ['d', 'available', '可选座'],
                ['d', 'unavailable', '已售出']
            ]
        },
        click: function() { /*点击事件*/
            if (this.status() == 'available') { /*可选座*/
                $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
                    .attr('id', 'cart-item4-' + this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart4);

                $counter4.text(sc4.find('selected').length + 1);
                $total4.text(recalculateTotal4(sc4) + price4);

                return 'selected';
            } else if (this.status() == 'selected') { /*已选中*/
                /*更新数量*/
                $counter4.text(sc4.find('selected').length - 1);
                /*更新总计*/
                $total4.text(recalculateTotal4(sc4) - price4);

                /*删除已预订座位*/
                $('#main4 #cart-item4-' + this.settings.id).remove();
                /*可选座*/
                return 'available';
            } else if (this.status() == 'unavailable') { /*已售出*/
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    /*已售出的座位*/
    sc4.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');

    /*计算总金额*/
    function recalculateTotal4(sc4) {
        var total4 = 0;
        sc4.find('selected').each(function() {
            total4 += price4;
        });

        return total4;
    }


    // 5号厅
    var price5 = 55; /*票价*/
    var $cart5 = $('#main5 #selected-seats'),
         /*座位区*/
         $counter5 = $('#main5 #counter'),
        /*票数*/
         $total5 = $('#main5 #total'); /*总计金额*/

    var sc5 = $('#main5 #seat-map').seatCharts({
        map: [ /*座位图*/
            'eeeeeeeeee',
            'eeeeeeeeee',
            '__________',
            'eeeeeeeeee',
            'eeeeeeeeee',
            '__eeeeeeee',
            'eeeeeeeeee',
            'eeeeeeeeee',
            'eeeeeeee__',
            'eeeeeeeeee'
        ],
        naming: {
            top: false,
            getLabel: function(character, row, column) {
                return column;
            }
        },
        legend: { /*定义图例*/
            node: $('#main5 #legend'),
            items: [
                ['e', 'available', '可选座'],
                ['e', 'unavailable', '已售出']
            ]
        },
        click: function() { /*点击事件*/
            if (this.status() == 'available') { /*可选座*/
                $('<li>' + (this.settings.row + 1) + '排' + this.settings.label + '座</li>')
                    .attr('id', 'cart-item5-' + this.settings.id)
                    .data('seatId', this.settings.id)
                    .appendTo($cart5);

                $counter5.text(sc5.find('selected').length + 1);
                $total5.text(recalculateTotal5(sc5) + price5);

                return 'selected';
            } else if (this.status() == 'selected') { /*已选中*/
                /*更新数量*/
                $counter5.text(sc5.find('selected').length - 1);
                /*更新总计*/
                $total5.text(recalculateTotal5(sc5) - price5);

                /*删除已预订座位*/
                $('#main5 #cart-item5-' + this.settings.id).remove();
                /*可选座*/
                return 'available';
            } else if (this.status() == 'unavailable') { /*已售出*/
                return 'unavailable';
            } else {
                return this.style();
            }
        }
    });
    /*已售出的座位*/
    sc5.get(['1_2', '4_4', '4_5', '6_6', '6_7', '8_5', '8_6', '8_7', '8_8', '10_1', '10_2']).status('unavailable');

    /*计算总金额*/
    function recalculateTotal5(sc5) {
        var total5 = 0;
        sc5.find('selected').each(function() {
            total5 += price5;
        });

        return total5;
    }


});